# -*- coding: utf-8 -*-
import sys, traceback
import logging
from lxml import etree
from xadmin.model import *
from xadmin.lib.base import *
from xadmin.lib.trazability import Trazability

class CRPRPRODTrazability(Trazability):
    def get(self):
        pass

    def getTrazaByProject(self, project):
        #try:
        project = Session.query(Project).get(project)
        c.client_requirements = Session.query(ClientRequirement).filter_by(project_id=project.id).all()
        c.product_requirements = Session.query(ProductRequirement).filter_by(project_id=project.id).all()
        c.products = Session.query(Product).filter_by(project_id=project.id).all()
        #Busca los id de
        #dict de la forma {namepr: [id_cr_realcionados]}
        dictlist = {}
        for cr in c.client_requirements:
            dictlist[cr.name] = [assoc.pr_id for assoc in cr.product_requirement_assoc]
        #print dictlist
        c.client_requirement_id_list = dictlist
        #Busca los id de
        #dict de la forma {nameprod: [id_pr_realcionados]}
        dictlist = {}
        for prod in c.products:
            dictlist[prod.name] = [assoc.pr_id for assoc in prod.products_requirements_assoc]
        #print dictlist
        c.product_id_list = dictlist
        return render('/trazability/crprprod.mako')
        #except:
        #    print "ERROR: ", sys.exc_info()[0]
        #    return None